package com.yixinsoft.basic.web.controller.manage;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by hqy on 2016/06/09
 */
@Controller
@RequestMapping("/manage")
public class LoginController {

	@RequestMapping(value = "/login")
	public String login(HttpServletRequest req, Model model) {
		String exceptionClassName = (String)req.getAttribute("shiroLoginFailure");
		String error = null;
		if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
			error = "用户名/密码错误";
		} else if (IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
			error = "用户名/密码错误";
		} else if (LockedAccountException.class.getName().equals(exceptionClassName)) {
			error = "用户被锁定，请联系管理员";
		} else if (ExcessiveAttemptsException.class.getName().equals(exceptionClassName)) {
			error = "登录失败次数过多，请过段时间后再试";
		} else if (exceptionClassName != null) {
			error = "其它错误：" + exceptionClassName;
		}
		model.addAttribute("error", error);
		return "manage/login";
	}
}
